﻿using Shop.Collect;
using Shop.Model.AttrTemplate;
using Shop.Model.DB;
using Shop.RemoteModel.AttrTemplate.Model;
using Shop.Service.Helper;
using Shop.Service.Interface;

namespace Shop.Service.lmpl
{
    internal class AttrTemplateService : IAttrTemplateService
    {
        private readonly IAttrTemplateCollect _Service;

        public AttrTemplateService (IAttrTemplateCollect service)
        {
            this._Service = service;
        }

        public long Add (AttrTemplateAdd add)
        {
            return this._Service.Add(add);
        }

        public void Delete (long id)
        {
            DBGoodsAttrTemplate source = this._Service.Get(id);
            this._Service.Delete(source);
        }

        public void Enable (long id)
        {
            DBGoodsAttrTemplate source = this._Service.Get(id);
            this._Service.Enable(source);
        }

        public AttrTemplate Get (long id)
        {
            return this._Service.Get<AttrTemplate>(id);
        }

        public AttrTemplateTree[] GetTrees (long categoryId, bool? isEnable)
        {
            AttrTemplateDto[] dtos = this._Service.GetsByCategoryId(categoryId, isEnable);
            return dtos.GetTree();
        }

        public Dictionary<long, int> SetSort (long id, int sort)
        {
            DBGoodsAttrTemplate source = this._Service.Get(id);
            return this._Service.SetSort(source, sort);
        }

        public void Stop (long id)
        {
            DBGoodsAttrTemplate source = this._Service.Get(id);
            this._Service.Stop(source);
        }

        public bool Update (long id, AttrTemplateSet set)
        {
            DBGoodsAttrTemplate source = this._Service.Get(id);
            return this._Service.Update(source, set);
        }
    }
}
